%creates 5 column matrix of force data 

%Output matrix column IDs:
%1: sub
%2: duration
%3: scenario
%4: cong_incong
%5: force
%6: norm
%7: value

clear all

%input matrix column IDs
%1: duration
%2: lab_cong_force
%3: lab_cong_norm
%4: lab_cong_value
%5: lab_incong_force
%6: lab_incong_norm
%7: lab_incong_value
%8: taxi_cong_force
%9: taxi_cong_norm
%10: taxi_cong_value
%11: taxi_incong_force
%12: taxi_incong_norm
%13: taxi_incong_value
%14: track_cong_force
%15: track_cong_norm
%16: track_cong_value
%17: track_incong_force
%18: track_incong_norm
%19: track_incong_value

%specify raw data file here
load('exp4_rawdata.mat')

raw_data=exp4rawdata;
temp=raw_data;
temp(:,1)=[];

%identify any subjects who gave no resonse
clean=~isnan(temp);
use=any(clean,2);

%create a new dataset eliminating those subjects
clean_data=raw_data(use==1,:);

%create a new conditions matrix
[rows,trash]=size(clean_data);
full_data=[];
for sub=1:rows
    %col 1: sub_num
    full_data(sub,1)=sub;
    %col 2: duration
    full_data(sub,2)=clean_data(sub,1);
    
    %find out which dilemma and condition subject is in
    if ~isnan(clean_data(sub,2))%if data is in the second column
        full_data(sub,3)=1;%set scenario to 1 (lab)
        full_data(sub,4)=1;%set cong_incong to 1 (cong)
        full_data(sub,5)=clean_data(sub,2);%get force response
        full_data(sub,6)=clean_data(sub,3);%get norm response
        full_data(sub,7)=clean_data(sub,4);%get value response
    elseif ~isnan(clean_data(sub,5))%if data is in the second column
        full_data(sub,3)=1;%set scenario to 1 (lab)
        full_data(sub,4)=2;%set cong_incong to 2 (incong)
        full_data(sub,5)=clean_data(sub,5);%get force response
        full_data(sub,6)=clean_data(sub,6);%get norm response
        full_data(sub,7)=clean_data(sub,7);%get value response
    elseif ~isnan(clean_data(sub,8))%if data is in the second column
        full_data(sub,3)=2;%set scenario to 2 (taxi)
        full_data(sub,4)=1;%set cong_incong to 1 (cong)
        full_data(sub,5)=clean_data(sub,8);%get force response
        full_data(sub,6)=clean_data(sub,9);%get norm response
        full_data(sub,7)=clean_data(sub,10);%get value response
    elseif ~isnan(clean_data(sub,11))%if data is in the second column
        full_data(sub,3)=2;%set scenario to 2 (taxi)
        full_data(sub,4)=2;%set cong_incong to 2 (incong)
        full_data(sub,5)=clean_data(sub,11);%get force response
        full_data(sub,6)=clean_data(sub,12);%get norm response
        full_data(sub,7)=clean_data(sub,13);%get value response
    elseif ~isnan(clean_data(sub,14))%if data is in the second column
        full_data(sub,3)=3;%set scenario to 3 (track)
        full_data(sub,4)=1;%set cong_incong to 1 (cong)
        full_data(sub,5)=clean_data(sub,14);%get force response
        full_data(sub,6)=clean_data(sub,15);%get norm response
        full_data(sub,7)=clean_data(sub,16);%get value response
    elseif ~isnan(clean_data(sub,17))%if data is in the second column
        full_data(sub,3)=3;%set scenario to 3 (track)
        full_data(sub,4)=2;%set cong_incong to 2 (incong)
        full_data(sub,5)=clean_data(sub,17);%get force response
        full_data(sub,6)=clean_data(sub,18);%get norm response
        full_data(sub,7)=clean_data(sub,19);%get value response
    end
end

%remove rows where scenario = zero
idx=full_data(:,3)==0;
full_data=full_data(idx~=1,:);

csvwrite('exp4_foranalysis.csv',full_data);